﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Xml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TFSTeamCityNotify.Entities;

namespace TFSTeamCityNotify.UnitTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class Web
    {
        public T LoadDataFile<T>(string filePath)
        {
            if (File.Exists(filePath))
            {
                try
                {
                    var document = new XmlDocument();
                    document.Load(filePath);

                    return Serializer.Deserialize<T>(document.InnerXml);
                }
                catch (Exception)
                {
                    throw new InvalidOperationException(filePath + " does not exist, fool!");
                }
            }

            return default(T);
        }

        [TestMethod]
        public void TestExecuteBuild()
        {
            var integration = new Integration();

            integration.ExecuteBuild("username", "password", "http://teamcityserver:port/ajax.html?add2Queue=bt6");
        }

        [TestMethod]
        public void TestSerialization()
        {
            var vcsCollection =
                new VCSCollection
                {
                    new VCS
                        {
                            Folder = "$/My/Source/Code/",
                            BuildTypes = new BuildTypeCollection
                            {
                                BuildTypeIDs = new List<string> { "bt1", "bt2" }
                            },
                            Exclusions = new ExclusionCollection
                            {
                                Paths = new List<string>{ "Src/MyRoadID.UnitTests/", "Database/" }
                            }
                        }
                };
        
            var s = Serializer.Serialize(vcsCollection);

            Assert.IsTrue(!string.IsNullOrEmpty(s));

        }
    }
}
